﻿using System;
using System.Globalization;
using ContractManagementSystem.BusinessLogic;
using ContractManagementSystem.Entity;


namespace ContractManagementSystem.Controls
{
    public partial class AddContractorControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            var contractorEntity = new ContractorEntity
                                       {
                                           UserId = UserBusiness.InitialUser(FullNameTextBox.Text, "Contractor"),
                                           Birthday = DateTime.Parse(BirthDateTextBox.Text, CultureInfo.CurrentCulture),
                                           FullName = FullNameTextBox.Text,
                                           Gender = GenderDropDownList.SelectedIndex,
                                           Email = EmailTextBox.Text,
                                           Address = AddressTextBox.Text,
                                           PhoneNumber1 = PhoneNumberTextBox.Text,
                                           PhoneNumber2 = PhoneNumbersTextBox.Text,
                                           Branch = BranchTextBox.Text
                                       };
            MessageLabel.Text = ContractorBusiness.Insert(contractorEntity) ? "Insert Success !" : "Insert False !";
            Submit.OnClientClick = "return ValidateTextBoxAll(" + MessageLabel.ClientID + ");";
        }
    }
}